package zone.haiwen.demo.domain.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import zone.haiwen.demo.domain.entity.vo.Myuser;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper;

import java.util.List;

/**
 * Description: Mapper接口
 * @author zhangHaiWen
 * @data 2021/7/7 19:51
 * @return
 **/
@Mapper
public interface MyuserMapper extends BaseMapper<Myuser> {
	/**
	 * Description
	 * @param name 姓名
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:14
	 * @return zone.haiwen.demo.domain.entity.vo.Myuser
	 **/
	@Select("select id, name, age, email from myuser where name = #{name}")
	Myuser getUserByName(@Param("name") String name);
	/**
	 * Description
	 * @param age 年龄
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:15
	 * @return java.util.List<zone.haiwen.demo.domain.entity.vo.Myuser>
	 **/
	@Select("select * from myuser where age = #{age}")
	List<Myuser> getUserByAge(@Param("age") int age);
	/**
	 * Description
	 * @param id 主键
	 * @param name 姓名
	 * @param age 年龄
	 * @param email 邮箱
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:18
	 * @return void
	 **/
	@Select("insert into myuser (id, name, age, email) values(#{id}, #{name}, #{age}, #{email})")
	void insertUser(@Param("id") Long id, @Param("name") String name, @Param("age") Integer age, @Param("email") String email);
	/**
	 * Description
	 * @param id 主键
	 * @param name 姓名
	 * @param age 年龄
     * @param email 邮箱
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:19
	 * @return void
	 **/
	@Select("update myuser set name = #{name}, age = #{age}, email = #{email} where id = #{id}")
	void updateUser(@Param("id") Long id, @Param("name") String name, @Param("age") Integer age, @Param("email") String email);
	/**
	 * Description
	 * @param id 主键
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:19
	 * @return void
	 **/
	@Select("delete from myuser where id = #{id}")
	void deleteUserById(@Param("id") Long id);
	/**
	 * Description
	 * @param id 主键
	 * @param name 姓名
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:19
	 * @return zone.haiwen.demo.domain.entity.vo.Myuser
	 **/
	@Select("\tselect id, name, age, email from myuser\n" +
			"\t\twhere id = #{id}\n" +
			"\t\t<if test=\"name != null\">\n" +
			"\t\t\tand name = #{name}\n" +
			"\t\t</if>")
	Myuser queryUserIf(@Param("id") Long id, @Param("name") String name);
	/**
	 * Description
	 * @param name 姓名
	 * @param age 年龄
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:20
	 * @return java.util.List<zone.haiwen.demo.domain.entity.vo.Myuser>
	 **/
	@Select("select id, name , age,email from myuser\n" +
			"\t\twhere\n" +
			"\t\t<choose>\n" +
			"\t\t\t<when test=\"name != null\">\n" +
			"\t\t\t\tname = #{name}\n" +
			"\t\t\t</when>\n" +
			"\t\t\t<when test=\"age != null\">\n" +
			"\t\t\t\tage = #{age}\n" +
			"\t\t\t</when>\n" +
			"\t\t\t<otherwise>\n" +
			"\t\t\t</otherwise>\n" +
			"\t\t</choose>")
	List<Myuser> queryUserChoose(@Param("name") String name, @Param("age") Integer age);
	/**
	 * Description
	 * @param name 年龄
	 * @param age 年龄
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:21
	 * @return java.util.List<zone.haiwen.demo.domain.entity.vo.Myuser>
	 **/
	@Select("\t\tselect id, name, age, email from myuser\n" +
			"\t\t<where>\n" +
			"\t\t\t<if test=\"name != null\">\n" +
			"\t\t\t\tname = #{name}\n" +
			"\t\t\t</if>\n" +
			"\t\t\t<if test=\"age != null\">\n" +
			"\t\t\t\tand age = #{age}\n" +
			"\t\t\t</if>\n" +
			"\t\t</where>")
	List<Myuser> queryUserWhere(@Param("name") String name, @Param("age") Integer age);
	/**
	 * Description
	 * @param list 输入参数
	 * @author zhangHaiWen
	 * @date 2021/7/8 10:21
	 * @return java.util.List<zone.haiwen.demo.domain.entity.vo.Myuser>
	 **/
	@Select("\t\tselect id, name, age, email from myuser\n" +
			"\t\twhere id in\n" +
			"\t\t<foreach collection=\"list\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">\n" +
			"\t\t\t#{item}\n" +
			"\t\t</foreach>")
	List<Myuser> queryUserForeach(@Param("list") List<Long> list);
}
